<template>
    <div class="Complaints">
      <!--<mt-header title="投诉建议">-->
      <!--</mt-header>-->
			<div class="header">
			  <van-nav-bar title="投诉建议" fixed  right-text left-arrow @click-left="onClickLeft"/>
			</div>
      <div class="Complaints_div">
        <span>被投诉人电话</span>
        <input type="number" placeholder="请输入被投诉人电话" oninput="if(value.length>11) value=value.slice(0,11)" maxlength="11"
         v-model.trim='aphone' @blur="checkPhoneNumber()"/>
      </div>
      <textarea placeholder="请输入你的投诉，建议内容，我们将持续关注改进" v-model.trim="textareaId"> </textarea>
      <p>注：恶意投诉将被注销账号</p>
      <button :disabled="!textareaId" :class="textareaId ? 'yf_button' : 'Complaints_button'" @click="saveAddress()">确认</button>
    </div>
</template>

<script>
    export default {
        name: "Complaints",
      data(){
          return{
            aphone: '',
            textareaId:'',
          }
      },
      methods: {
        //  将建议传给后台
        async saveAddress(){
          let this_ = this;
          var userList=JSON.parse(localStorage.getItem('userInfo'))
          this.userList=userList
          let params = {
            from_user_id:userList.userId,
            phone:this_.aphone,
            info:this_.textareaId,
          };
          const res = await this.$axios.post(this.$api.insertComplaintsData, params);
          if (res.success) {
            this.$toast(res.msg);
          } else {
            this.$toast(res.msg);
          }
        },
        //表单初始化
        checkPhoneNumber: function () {
          let reg = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/;
          if (reg.test(this.aphone) == false) {
            this.aphone = '';
            this.$message({
              type : 'error',
              message : '请输入正确的手机号'
            });
          }
        },
		//返回
		onClickLeft() {
		  this.$router.go(-1);//返回上一层
		},
      },
      created:function () {
        //隐藏公用底部
        this.$emit('public_footer', false);
          setTitle('投诉建议')
      },

    }
</script>

<style scoped>
  @import '../../assets/css/index.css';
</style>
